import { defineStore } from 'pinia'
import { ref } from 'vue'

export const guanzhuStore = defineStore(
  'guanzhuStore',
  () => {
    const guanzhu = ref<any>('')
    const guanzhuid = (val: any) => {
      console.log('userid被存进pinia')
      guanzhu.value = val
    }

    const item = ref<any>({})
    const itemid = (val: any) => {
      console.log(item,'item被存进pinia')
      item.value = val
    }

    // 要返回
    return {
      guanzhu,
      guanzhuid,
      itemid,
      item,
    }
  },
  // TODO: 持久化   这个主要在pinia里设置后就会自动存到小程序配置里。
  {
    // 网页端配置
    // persist: true,
    // 小程序端配置
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
      },
    },
  },
)
